github-base
![Linux Build Status](https://img.shields.io/travis/jonschlinkert/github-base.svg?style=flat&label=Travis)
JavaScript wrapper that greatly simplifies working with GitHub's API.
Install
Install with npm:
$ npm install --save github-base
Heads up!
This lib was completely refactored in v0.2.0
. Please see the API documentation for more details.
About
This library provides the necessary methods for creating your own GitHub API library or more specific functionality built on top of these methods.
- .request: the base handler all of the GitHub API VERBS:
GET
, PUT
, POST
, DELETE
, PATCH
- .get: proxy for
request('GET', path, data, cb)
- .paged: makes repeat
.get()
requests until the page of data has been retrieved. - .del: proxy for
request('DEL', path, data, cb)
- .patch: proxy for
request('PATCH', path, data, cb)
- .post: proxy for
request('POST', path, data, cb)
- .put: proxy for
request('PUT', path, data, cb)
Usage
var GitHub = require('github-base');
var github = new GitHub({
username: YOUR_USERNAME,
password: YOUR_PASSWORD,
});
var github = new GitHub({
token: YOUR_TOKEN
});
var github = new GitHub({
bearer: YOUR_JWT
});
Why another "GitHub API" lib?
Every other GitHub API library I found either had a huge dependency tree, tries to be everything to everyone, was too bloated with boilerplace code, was too opinionated or not maintained.
API
Create an instance of GitHub
with the given options.
Params
Example
var GitHub = require('github-base');
var github = new GitHub(options);
Uses simple-get to make a single request to the GitHub API, based on the provided settings. Supports any of the GitHub API VERBs:
Params
method
{String}: The http VERB to useurl
{String}: GitHub API URL to use.options
{Options}: Request options.cb
{Function}
Example
github.request('GET', '/user/orgs', function (err, res) {
});
Makes a single GET
request to the GitHub API based on the provided settings.
Params
path
{String}: path to append to the GitHub API URL.options
{Options}: Request options.cb
{Function}
Example
github.get('/user/orgs', function (err, res) {
});
github.get('/gists', function (err, res) {
});
Performs a request using simple-get, and then if necessary requests additional paged content based on the response. Data from all pages are concatenated together and buffered until the last page of data has been retrieved.
Params
path
{String}: path to append to the GitHub API URL.cb
{Function}
Example
var url = '/user/repos?type=all&per_page=1000&sort=updated';
github.paged(url, function(err, res) {
console.log(res);
});
Makes a single DELETE
request to the GitHub API based on the provided settings.
Params
path
{String}: path to append to the GitHub API URL.options
{Options}: Request options.cb
{Function}
Example
github.del('/user/following/someoneelse', function(err, res) {
console.log(res);
});
Makes a single PATCH
request to the GitHub API based on the provided settings.
Params
path
{String}: path to append to the GitHub API URL.options
{Options}: Request options.cb
{Function}
Example
var fs = require('fs');
var opts = {files: {'readme.md': { content: '# My Readme...' }}};
github.patch('/gists/bd139161a425896f35f8', opts, function(err, res) {
console.log(err, res);
});
Makes a single POST
request to the GitHub API based on the provided settings.
Params
path
{String}: path to append to the GitHub API URL.options
{Options}: Request options.cb
{Function}
Example
var opts = { name: 'new-repo-name' };
github.post('/user/repos', opts, function(err, res) {
console.log(res);
});
Makes a single PUT
request to the GitHub API based on the provided settings.
Params
path
{String}: path to append to the GitHub API URL.options
{Options}: Request options.cb
{Function}
Example
github.put('/user/following/jonschlinkert', function(err, res) {
console.log(res);
});
Static method for inheriting the prototype and static methods of the Base
class. This method greatly simplifies the process of creating inheritance-based applications. See static-extend for more details.
Params
Ctor
{Function}: constructor to extend
Example
var GitHub = require('github-base');
function MyApp() {
GitHub.call(this);
}
GitHub.extend(MyApp);
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Contributors
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.4.3, on April 06, 2017.